<?php

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see 
 * <http://www.gnu.org/licenses/>.
*/


// no direct access
defined('_JEXEC') or die('Restricted access');


JHTML::_('behavior.tooltip');

// Set toolbar items for the page
JToolBarHelper::title(JText::_('Gallery Manager'), 'generic.png');
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::deleteList();
JToolBarHelper::editListX();
JToolBarHelper::addNewX();


?>
<form action="index.php" method="post" name="adminForm">
	<table>
		<tr>
			<td width="100%">
				<?php echo JText::_('Filter'); ?>:
				<input class="text_area" id="search" name="search" onchange="document.adminForm.submit();" type="text" value="<?php echo $this->lists['search'];?>" />
				<button onclick="this.form.submit();"><?php echo JText::_('Go'); ?></button>
				<button onclick="document.getElementById('search').value='';this.form.getElementById('filter_catid').value='0';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_('Reset'); ?></button>
			</td>
			<td nowrap="nowrap">
<?php
echo $this->lists['catid'];
echo $this->lists['state'];
?>
			</td>
		</tr>
	</table>
	<div id="editcell">
		<table class="adminlist">
			<thead>
				<tr>
					<th width="5"><?php echo JText::_('NUM'); ?></th>
					<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" /></th>
					<th class="title" width="120"><?php echo JText::_('Image'); ?></th>
					<th class="title"><?php echo JHTML::_('grid.sort',  'Title', 'i.title', $this->lists['order_Dir'], $this->lists['order']); ?></th>
					<th width="5%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'Published', 'i.published', $this->lists['order_Dir'], $this->lists['order']); ?></th>
					<th width="8%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'Order', 'i.ordering', $this->lists['order_Dir'], $this->lists['order']); ?><?php echo JHTML::_('grid.order',  $this->items); ?></th>
					<th width="15%"  class="title"><?php echo JHTML::_('grid.sort',  'Category', 'category', $this->lists['order_Dir'], $this->lists['order']); ?></th>
					<th width="5%"><?php echo JHTML::_('grid.sort',  'Hits', 'i.hits', $this->lists['order_Dir'], $this->lists['order']); ?></th>
					<th width="1%" nowrap="nowrap"><?php echo JHTML::_('grid.sort',  'ID', 'i.id', $this->lists['order_Dir'], $this->lists['order']); ?></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="9"><?php echo $this->pagination->getListFooter(); ?></td>
				</tr>
			</tfoot>
			<tbody>
<?php
$k = 0;
for ($i=0, $n=count($this->items); $i < $n; $i++)
{
	$row = &$this->items[$i];

	$link 	= JRoute::_('index.php?option=com_gallery&view=image&task=edit&cid[]='. $row->id);

	$checked 	= JHTML::_('grid.checkedout',   $row, $i);
	$published 	= JHTML::_('grid.published', $row, $i);

	$ordering = ($this->lists['order'] == 'i.ordering');

	$row->cat_link 	= JRoute::_('index.php?option=com_categories&section=com_gallery&task=edit&type=other&cid[]='. $row->catid);
?>
				<tr class="<?php echo "row$k"; ?>">
					<td><?php echo $this->pagination->getRowOffset($i); ?></td>
					<td><?php echo $checked; ?></td>
					<td><img src="<?php echo JURI::base(), '../', $row->thumb_url; ?>"/></td>
					<td>
<?php
	if (JTable::isCheckedOut($this->user->get ('id'), $row->checked_out)) {
		echo $row->title;
	} else {
	?>
						<a href="<?php echo $link; ?>" title="<?php echo JText::_('Edit Image Details'); ?>"><?php echo $row->title; ?></a>
	<?php
	}
?>
					</td>
					<td align="center"><?php echo $published;?></td>
					<td class="order">
						<span><?php echo $this->pagination->orderUpIcon($i, ($row->catid == @$this->items[$i-1]->catid),'orderup', 'Move Up', $ordering); ?></span>
						<span><?php echo $this->pagination->orderDownIcon($i, $n, ($row->catid == @$this->items[$i+1]->catid), 'orderdown', 'Move Down', $ordering); ?></span>
						<?php $disabled = $ordering ?  '' : 'disabled="disabled"'; ?>
						<input type="text" name="order[]" size="5" value="<?php echo $row->ordering;?>" <?php echo $disabled ?> class="text_area" style="text-align: center" />
					</td>
					<td><a href="<?php echo $row->cat_link; ?>" title="<?php echo JText::_('Edit Category'); ?>"><?php echo $row->category; ?></a></td>
					<td align="center"><?php echo $row->hits; ?></td>
					<td align="center"><?php echo $row->id; ?></td>
				</tr>
<?php
	$k = 1 - $k;
}
?>
			</tbody>
		</table>
	</div>

	<input type="hidden" name="option" value="com_gallery" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>
